package com.wx.day05.Annotation_aop.test2;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Aroundaspect {
    //不推荐 没有共享的参数 单独写比较好 如果要共享变量的话 用环绕通知比较好
    @Around(value = "execution(* com.wx.day05.Annotation_aop.test2.*.*(..))")
    public Object test(ProceedingJoinPoint joinPoint)
    {
        Object[] args = joinPoint.getArgs();
        Object res = null;
        long start = System.currentTimeMillis();
        try {
            //1.前置通知
            System.out.println("start");
            res = joinPoint.proceed();
        }catch (Throwable e){
            System.out.println("error");
        }finally {
            long end = System.currentTimeMillis();
            System.out.println("end consume " + (end - start) + " ms");
        }
        return res;
    }
}
